const obj = {
  v: 123,
  foo() {
    console.log("o -> foo", this.v);
    return this.v * 2;
  },
};
// 修改对象 o 的 m 方法，加上 trace 效果
function trace(o, m) {
  let original = o[m];
  o[m] = function (...args) {
    console.log("Entering", m);
    const result = original.apply(o, args);
    console.log("Exiting", m);
    return result;
  };
}
const v1 = obj.foo(); // o -> foo 123
console.log(`v1 = ${v1}`); // 246
trace(obj, "foo");
const v2 = obj.foo(); // Entering foo \n o -> foo 123 \n Exiting foo
console.log(`v2 = ${v2}`); // 246
